# test iot crud

import os
import django
from django.conf import settings
import sys
from datetime import datetime
if not settings.configured:
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'matrix.settings')  # 添加了环境
    django.setup()  # 初始化 Django 环境


from serverworker.models import electricity_meter,Temperature_humidity
from django.http import JsonResponse



a = Temperature_humidity.objects.get(id=2) #当name="m8" 存在多个会报错
print("当前行号：",sys._getframe().f_lineno,a.temperature,a.humidity, a.create_time)


def ChartDataView():
    if 1:
        start_date = '2025-07-16 19:35:02.777354'
        end_date = '2025-07-17 19:35:02.777354'


        # 查询数据
        data = electricity_meter.objects.filter(
            create_time__gte=start_date,
            create_time__lt=end_date
        ).order_by('create_time')

    u = data.values_list('u', flat=True)
    i = data.values_list('i', flat=True)
    q = data.values_list('q', flat=True)
    w = data.values_list('w', flat=True)
    print(u,i,q,w)

ChartDataView()